package mlp.game.cherries;

import mlp.game.cherries.R;

import com.overkill.game.RenderView;
import com.playtomic.android.api.Playtomic;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.graphics.Typeface;
import android.media.AudioManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.widget.RelativeLayout;

public class IntroActivity extends Activity {
	public static final String URL_TWITTER = "https://twitter.com/OV3RK1LL";
	public static final String URL_FACEBOOK = "http://www.facebook.com/PonyGameCollection";
	public static final String URL_PAYPAL = "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=UYQJSSAKZNMFY";
	
	 @Override
	 public void onCreate(Bundle savedInstanceState) {
		 super.onCreate(savedInstanceState);
		 setVolumeControlStream(AudioManager.STREAM_MUSIC);
	     setContentView(R.layout.intro);
	     Typeface celestia = Typeface.createFromAsset(getAssets(), RenderView.TYPEFACE_PATH);
	     Tools.setTypeFace(this, celestia, R.id.btnStart, R.id.btnHelp, R.id.btnDonate, R.id.btnFacebook, R.id.btnTwitter, R.id.textView1, R.id.textView2);
	     try {
	    	 Playtomic.getInstance(
	    			 427759, 
	    			 "6e6684f2ef1a4bd8", 
	    			 "5cb7664a80044a9ab790cf354318f9", 
	    			 this);
	    	 Playtomic.Log().view();
	     } catch (Exception e) {
	    	 e.printStackTrace();
	     }	  
	     AlphaAnimation a = new AlphaAnimation(0, 0.97f);
	     a.setDuration(1500);
	     a.setFillAfter(true);
	     ((RelativeLayout)findViewById(R.id.layoutMenu)).startAnimation(a);
	 }
	 
	 public void onStartClick(View view) {
		 Intent i = new Intent(this, GameActivity.class);
		 i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
		 overridePendingTransition(0, 0);
		 finish();
		 overridePendingTransition(0, 0);
		 startActivity(i);
	}
	 		
	public void onHelpClick(View view) {
		new AlertDialog.Builder(this)
			.setIcon(android.R.drawable.ic_dialog_info)
			.setTitle(R.string.btnHelp)
			.setMessage(R.string.help_dialog_message)
			.setPositiveButton(android.R.string.yes, null)
			.show();
	}
	 
	 public void onExtraClick(View view) {
			Intent i = null;
			switch (view.getId()) {
			case R.id.btnDonate:
				i = new Intent(Intent.ACTION_VIEW, Uri.parse(URL_PAYPAL));
				break;
			case R.id.btnFacebook:
				i = new Intent(Intent.ACTION_VIEW, Uri.parse(URL_FACEBOOK));
				break;
			case R.id.btnTwitter:
				i = new Intent(Intent.ACTION_VIEW, Uri.parse(URL_TWITTER));
				break;
			default:
				break;
			}
			if(i != null)
				startActivity(i);
		}	
	
	 @Override
	protected void onDestroy() {
		 setVolumeControlStream(AudioManager.USE_DEFAULT_STREAM_TYPE);
		super.onDestroy();
	}
}
